#pragma once
#include "Component.h"
#include "Transform.h"

namespace DYEngine
{
	enum class CameraType
	{
		Ortho,	// 正交
		Proj,	// 透视
	};

	class Camera : public Component
	{
	public:
		Camera();
		Camera(CameraType type);
		// 获取投影矩阵
		glm::mat4 GetProjMatrix();
		glm::mat4 GetVPMatrix();
		virtual ~Camera();
	public:
		void SetZNear(float zNear)
		{
			mZNear = zNear;
			isDirty = true;
		}

		void SetZFar(float zFar)
		{
			mZFar = zFar;
			isDirty = true;
		}

		void SetAspect(float aspect)
		{
			mAspect = aspect;
			isDirty = true;
		}

		void SetFov(float fov)
		{
			mFov = fov;
			isDirty = true;
		}

		void SetSize(float size)
		{
			mSize = size;
			isDirty = true;
		}

		void SetProjCamera(float fov, float aspect, float zNear, float zFar)
		{
			isDirty = true;
			mFov = fov;
			mAspect = aspect;
			mZNear = zNear;
			mZFar = zFar;
		}

		void SetOrthoCamera(float size, float aspect, float zNear, float zFar)
		{
			isDirty = true;
			mAspect = aspect;
			mZNear = zNear;
			mZFar = zFar;
			mSize = size;
		}
	public:
		void Init();
		void Enable();
		void Update();
		void Disable();
		void Destroy();
	public:
		static int sWidth;
		static int sHeight;
		static Camera* GetMainCamera();
		static void SetMainCamera(Camera* pCamera);
	private:
		// 摄像机近平面
		float mZNear = 0.001f;
		// 摄像机远平面
		float mZFar = 1000.0f;
		// 摄像机宽高比
		float mAspect = 0.8f;
		// 摄像机透视视野
		float mFov = 60.0f;
		// 摄像机的正交高度
		float mSize = 10.0f;

		bool isDirty = false;
		glm::mat4x4 mPerspMat;
		glm::mat4x4 mOrthoMat;

		CameraType mType = CameraType::Proj;
	};
}
